package com.two.screen.water.balance.widget.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import android.widget.ImageView
import android.widget.TextView
import com.two.screen.water.balance.R
import com.two.screen.water.balance.bean.BaseData
import com.two.screen.water.balance.ui.App
import com.two.screen.water.balance.utils.DialogUtil
import com.two.screen.water.balance.utils.ZXingUtils


class SaleGoodsReportDialog(context: Context) : Dialog(context, R.style.ChooseDialog) {

    private var mSaleGoodsReportDialogListener: SaleGoodsReportDialogListener? = null
    private var mGoBackIv: ImageView? = null
    private var mQrIv: ImageView? = null
    private var mCancel: TextView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_sale_goods_report)
        this.setCanceledOnTouchOutside(false)

        val window = window
        if (window != null) {
            val attributes = window.attributes
            attributes.width = App.screenWidth
            window.attributes = attributes
            window.setGravity(Gravity.CENTER)
        }

        mGoBackIv = findViewById(R.id.dialog_close_iv)
        mQrIv = findViewById(R.id.dialog_qr_iv)
        mCancel = findViewById(R.id.dialog_cancel_tv)

        mGoBackIv?.setOnClickListener {
            dismiss()
        }
        mCancel?.setOnClickListener {
            dismiss()
        }
    }

    fun setDialogInfo(data: BaseData?) {
        mQrIv?.setImageBitmap(
            ZXingUtils.createQRCodeBitmap(
                "商品销售报表正在创建中...接口都还没出，别等了。", 400,
                "UTF-8",
                "H",
                "2",
                Color.BLACK,
                Color.WHITE,
                null, null, 0.2f
            )
        )
    }


    fun setLoginOutDialogListener(l: SaleGoodsReportDialogListener) {
        mSaleGoodsReportDialogListener = l
    }


    interface SaleGoodsReportDialogListener {
        fun onConfirm()
    }
    override fun show() {
        super.show()
        //隐藏状态栏
        window?.let { DialogUtil.hideNavigationBar(it) }
    }
}
